package com.cart.seon.usbconnection.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbManager;
import android.widget.Toast;

public class USBReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        // usb
        if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
            // usb device attached
            Toast.makeText(context, "USB设备已插入", Toast.LENGTH_SHORT).show();
        } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
            // usb device detached
            Toast.makeText(context, "USB设备已拔出", Toast.LENGTH_SHORT).show();
        }
        // 插入识别.
        if (Intent.ACTION_MEDIA_MOUNTED.equals(action)) {
            Toast.makeText(context, "USB设备已插入", Toast.LENGTH_SHORT).show();
        } else if (Intent.ACTION_MEDIA_UNMOUNTED.equals(action)) {
            Toast.makeText(context, "USB设备已拔出", Toast.LENGTH_SHORT).show();
        }
    }
}
